<template>
  <t-link
    v-if="userStore.userInfo.id==1"
    theme="primary"
    @click="handleOpenDialog('update', { orderId: props.id })"
  >
    手动
  </t-link>
  <!-- 自定义对话框 -->
  <custom-dialog
    ref="customDialogRef"
    v-slot="{ formData }"
    :api-map="{ update: setProduct }"
    header="手动"
    @request-success="handleDialogRequestSuccess"
  >
    <t-form-item label="期款" name="payNumber" :rules="[{ required: true, message: '请选择期款' }]">
      <t-select
        v-model:value="formData.payNumber"
        :options="[
          {label:'首期款',value:1},
          {label:'二期款',value:2},
          {label:'三期款',value:3},
          {label:'尾款',value:4},
        ]"
        placeholder="请选择期款"
        clearable
        filterable
        @clear="formData.payNumber = null"
      />
    </t-form-item>
    
  </custom-dialog>
</template>

<script setup lang="ts">
import { useTemplateRef } from 'vue';

import { setProduct } from '@/api/order/basic';
import CustomDialog from '@/components/custom/dialog/index.vue';
import { useDictionaryStore, useUserStore } from '@/store';
// 用户仓库
const userStore = useUserStore();
// 字典仓库
const dictionaryStore = useDictionaryStore();
// props
const props = defineProps({
  // 订单id
  id: {
    type: Number,
    required: true,
  },
});
// emits
const emits = defineEmits(['requestSuccess']);
// 自定义对话框ref
const customDialogRef = useTemplateRef('customDialogRef');
// 处理打开对话框
const handleOpenDialog = (mode: 'create' | 'read' | 'update', params: Record<string, any>) => {
  customDialogRef.value.open(mode, params);
};
// 处理对话框请求成功
const handleDialogRequestSuccess = (result: Record<string, any>) => {
  emits('requestSuccess', result);
};
</script>
